package com.teacher.hong.service.impl;

import com.teacher.hong.dao.UserDao;
import com.teacher.hong.entity.User;
import com.teacher.hong.exception.ServiceValidationException;
import com.teacher.hong.service.IUserService;
import org.springframework.stereotype.Service;
import javax.annotation.Resource;
import java.sql.SQLException;

@Service("userService")
public class UserServiceImpl implements IUserService {

    @Resource
    UserDao userDao;

//    public void setUserDao(UserDao userDao) {
//        this.userDao = userDao;
//    }

    @Override
    public void login(User user) throws ServiceValidationException {
        try {
            User loginUser = userDao.selectByAccount(user.getAccount());
            if (loginUser == null) {
                //未找到该用户
                throw new ServiceValidationException("登录失败，账号不存在，请前往注册", 401);
            }
            if (!loginUser.getPassword().equals(user.getPassword())) {
                //检测到用户，但是密码错误
                throw new ServiceValidationException("登录失败，账号或密码错误", 401);
            }
        } catch (SQLException throwables) {
            throwables.printStackTrace();
        }

    }
}
